package frameworks.widgets
{
	public class Result
	{
		public var valid:Boolean = false;
		public var data:Object = "";
		public var errors:Object = {};
		public var attachments:Array = [];
		public var source:Object = "";
		
		public function Result(code:Object)
		{
			decode(code);
		}
		public function decode(code:Object):void{
			this.valid = false;
			this.data = {};
			this.errors = {};
			this.attachments = [];
			this.source = "";
			if(code.hasOwnProperty("valid")){this.valid = code.valid;}
			if(code.hasOwnProperty("data")){this.data = code.data;}
			if(code.hasOwnProperty("errors")){this.errors = code.errors;}
			if(code.hasOwnProperty("attachment")){this.attachments = code.attachments;}
			if(code.hasOwnProperty("source")){this.source = code.source;}
		}
		public function formatErrorMessage():String{
			var msg:String = "";
			for(var eid:String in this.errors){
				var item:* = this.errors[eid];
				msg += (item is String)? item : item.note;
			}
			return msg;
		}
	}
}